#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Test lockmanager
#
TestName="lockmgr-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-confs

grep '#define _USE_LOCKMGR 1' $src/src/config.h > /dev/null
if [ $? != 0 ]; then
    echo "lockmanager disabled"
    exit 0
fi

#
# Zap out any schedule in default conf file so that
#  it doesn't start during our test
#
outf="$tmp/sed_tmp"
echo "s%  Schedule =%# Schedule =%g" >${outf}
cp $scripts/bacula-dir.conf $tmp/1
sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf

start_test

make -C $src/src/lib lockmgr_test > /dev/null
if [ -f $src/src/lib/.libs/lockmgr_test ]; then
    LD_LIBRARY_PATH=$src/src/lib/.libs $src/src/lib/.libs/lockmgr_test > $tmp/1 2> $tmp/2
else 
    $src/src/lib/lockmgr_test > $tmp/1 2> $tmp/2
fi

estat=$?

if [ "$debug" = 1 ]; then
    cat $tmp/1
fi

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
setdebug level=15 dir
setdebug level=15 storage=File1
status dir
status storage=File1
.die deadlock storage=File1
.die deadlock dir
quit
END_OF_DATA

run_bacula
stop_bacula

nb=`ls $working/*.traceback $working/*.traceback | wc -l`
if [ $nb != 4 ]; then
    print_debug "ERROR: Should find 4 traces, not $nb"
    estat=1
fi

notracedump=yes
export notracedump
end_test
